home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 11.3 KB | 392 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWSclBar.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWSCLBAR_H
- #include "FWSclBar.h"
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(FWCONTRH_H)
- #include "FWContrH.h"
- #endif
-
- #if defined(FW_BUILD_WIN) && !defined(FWCNTRHW_H)
- #include "FWCntrHW.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- #ifndef FWSCLNOT_H
- #include "FWSclNot.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWGRGLOB_H
- #include "FWGrGlob.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- // ----- Platform Includes -----
-
- #if defined(FW_BUILD_MAC) && !defined(__CONTROLS__)
- #include <Controls.h>
- #endif
-
- #ifdef FW_BUILD_WIN
- #include <Windows.h>
- #endif
-
- //========================================================================================
- // Runtime Informations
- //========================================================================================
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwgadgts
- #endif
-
- FW_DEFINE_CLASS_M2(FW_CScrollBar, FW_CGadget, FW_MNotifier)
-
- //========================================================================================
- // CLASS FW_CScrollBar
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::FW_CScrollBar
- //----------------------------------------------------------------------------------------
-
- FW_CScrollBar::FW_CScrollBar(Environment* ev,
- FW_CView* container, ODID id,
- const FW_CRect& bounds) :
- FW_MNotifier(),
- FW_CGadget(ev, container, id, bounds),
- fScrollBarHelper(NULL),
- fMinorScrollUnits(FW_IntToFixed(1)),
- fMajorScrollUnits(FW_IntToFixed(1)),
- fScrollNotificationToken(0)
- {
- #ifdef FW_BUILD_MAC
- fScrollBarHelper = new FW_CPrivMacScrollBarHelper
- (ev, FW_TYPEID_FROM_TYPE(FW_CPrivMacScrollBarHelper), this);
- #endif
-
- #ifdef FW_BUILD_WIN
- fScrollBarHelper = new FW_CPrivWinScrollBarHelper
- (ev, FW_TYPEID_FROM_TYPE(FW_CPrivWinScrollBarHelper), this);
- #endif
-
- ODSession* session = GetFrame(ev)->GetPart(ev)->GetSession(ev);
- fScrollNotificationToken = session->Tokenize(ev, FW_CScrollNotification::kName);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::~FW_CScrollBar
- //----------------------------------------------------------------------------------------
-
- FW_CScrollBar::~FW_CScrollBar()
- {
- delete fScrollBarHelper;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::LocationChanged
- //----------------------------------------------------------------------------------------
-
- void FW_CScrollBar::LocationChanged(Environment *ev, const FW_CPoint &oldLocation)
- {
- FW_UNUSED(oldLocation);
-
- #ifdef FW_BUILD_WIN
- FW_CViewContext gc(ev, this, GetFrame(ev)->GetActiveFacet(ev));
-
- FW_SPlatformPoint wndLocation = gc.ContentToCanvas(FW_kZeroPoint);
- FW_CPoint size = GetSize(ev);
- FW_SPlatformPoint wndSize = gc.ContentToCanvas(size.x, size.y);
- fScrollBarHelper->Move(wndLocation, wndSize);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::SizeChanged
- //----------------------------------------------------------------------------------------
-
- void FW_CScrollBar::SizeChanged(Environment *ev, const FW_CPoint &oldSize)
- {
- FW_UNUSED(oldSize);
-
- #ifdef FW_BUILD_WIN
- FW_CViewContext gc(ev, this, GetFrame(ev)->GetActiveFacet(ev));
-
- FW_SPlatformPoint wndLocation = gc.ContentToCanvas(FW_kZeroPoint);
- FW_CPoint size = GetSize(ev);
- FW_SPlatformPoint wndSize = gc.ContentToCanvas(size.x, size.y);
- fScrollBarHelper->Move(wndLocation, wndSize);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::ScrollPositionChanged
- //----------------------------------------------------------------------------------------
-
- void FW_CScrollBar::ScrollPositionChanged(Environment *ev, FW_CFixed absolute, FW_CFixed delta, FW_Boolean shouldScroll)
- {
- // ----- Figure out which direction we're scrolling
-
- FW_CScrollNotification::Direction direction = FW_CScrollNotification::kHorizontal;
- FW_CRect bounds = GetBounds(ev);
- if (bounds.Height() > bounds.Width())
- direction = FW_CScrollNotification::kVertical;
-
- // ----- Notify interested parties of the changes in scroll position
-
- FW_CScrollNotification notification(FW_CInterest(this, fScrollNotificationToken),
- direction, absolute, delta, shouldScroll);
- Notify(notification);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::GetDefaultScrollBarSize
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CScrollBar::GetDefaultScrollBarSize()
- {
- #ifdef FW_BUILD_MAC
- return FW_CPoint(FW_IntToFixed(15), FW_IntToFixed(15));
- #endif
- #ifdef FW_BUILD_WIN
- return FW_CPoint(FW_IntToFixed(::GetSystemMetrics(SM_CXHSCROLL)),
- FW_IntToFixed(::GetSystemMetrics(SM_CXVSCROLL)));
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::Draw
- //----------------------------------------------------------------------------------------
-
- void FW_CScrollBar::Draw(Environment *ev, ODFacet* facet, ODShape* invalidShape)
- {
- #ifdef FW_BUILD_MAC
- FW_CViewContext gc(ev, this, facet, invalidShape);
-
- FW_SPlatformPoint qdPoint = gc.LogicalToDevice(FW_kZeroPoint);
- FW_SPlatformPoint qdSize;
- GetSize(ev).AsPlatformPoint(qdSize);
- ODPlatformWindow window = facet->GetWindow(ev)->GetPlatformWindow(ev);
- fScrollBarHelper->Draw(window, qdPoint, qdSize);
- #endif
-
- #ifdef FW_BUILD_WIN
- FW_UNUSED(facet);
- FW_UNUSED(invalidShape);
- // Windows handles updating controls automatically
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::DoActivateEvent
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CScrollBar::DoActivateEvent(Environment *ev,
- const FW_CActivateEvent& theActivateEvent)
- {
- #ifdef FW_BUILD_MAC
- ODFacet* facet = theActivateEvent.GetFacet(ev);
- FW_CViewContext gc(ev, this, facet);
-
- FW_SPlatformPoint qdPoint = gc.LogicalToDevice(FW_kZeroPoint);
- FW_SPlatformPoint qdSize;
- GetSize(ev).AsPlatformPoint(qdSize);
- ODPlatformWindow window = facet->GetWindow(ev)->GetPlatformWindow(ev);
-
- if (theActivateEvent.IsActivating(ev)) {
- fScrollBarHelper->Show(window, qdPoint, qdSize);
- }
- else {
- fScrollBarHelper->Hide(window, qdPoint, qdSize);
- }
-
- #endif
-
- #ifdef FW_BUILD_WIN
- // [LSD] to do
- #endif
- return FALSE; // let other views handle activate events
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::DoMouseDown
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CScrollBar::DoMouseDown(Environment *ev, const FW_CMouseEvent& theMouseEvent)
- {
- #ifdef FW_BUILD_MAC
- ODFacet* odFacet = theMouseEvent.GetFacet(ev);
- FW_CViewContext gc(ev, this, odFacet);
-
- FW_CPoint canvasWhere = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kWindow);
-
- {
- // Take into account the origin offset for pattern alignment. [AMB]
- FW_CAcquiredODTransform aqTransform(odFacet->CreateTransform(ev));
-
- ODPlatformCanvas plfmCanvas = gc.GetPlatformCanvas();
- FW_CPoint offset(
- FW_IntToFixed(plfmCanvas->portRect.left),
- FW_IntToFixed(plfmCanvas->portRect.top));
-
- ODPoint odOffset = offset;
- aqTransform->MoveBy(ev, &odOffset);
-
- canvasWhere.Transform(ev, aqTransform);
- }
-
- FW_SPlatformPoint qdControlPosition = gc.LogicalToDevice(FW_kZeroPoint);
- FW_SPlatformPoint qdWhere;
- canvasWhere.AsPlatformPoint(qdWhere);
- ODPlatformWindow window = odFacet->GetWindow(ev)->GetPlatformWindow(ev);
-
- FW_SPlatformPoint qdSize;
- GetSize(ev).AsPlatformPoint(qdSize);
-
- fScrollBarHelper->MouseDown(window, qdWhere, qdControlPosition, qdSize);
- return TRUE;
- #endif
-
- #ifdef FW_BUILD_WIN
- FW_UNUSED(theMouseEvent);
- // Windows handles mouse events automatically
- return FALSE;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::SetMinorScrollUnits
- //----------------------------------------------------------------------------------------
-
- void FW_CScrollBar::SetMinorScrollUnits(Environment *ev, FW_CFixed units)
- {
- fMinorScrollUnits = units;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::SetMajorScrollUnits
- //----------------------------------------------------------------------------------------
-
- void FW_CScrollBar::SetMajorScrollUnits(Environment *ev, FW_CFixed units)
- {
- fMajorScrollUnits = units;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::SetScrollMax
- //----------------------------------------------------------------------------------------
-
- void FW_CScrollBar::SetScrollMax(Environment *ev, FW_CFixed units)
- {
- FW_ASSERT(fScrollBarHelper);
-
- #ifdef FW_BUILD_MAC
- fScrollBarHelper->SetMax(units.AsInt());
- #endif
-
- #ifdef FW_BUILD_WIN
- int min, max;
- fScrollBarHelper->GetScrollRange(min, max);
- fScrollBarHelper->SetScrollRange(min, units.AsInt());
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::SetScrollMin
- //----------------------------------------------------------------------------------------
-
- void FW_CScrollBar::SetScrollMin(Environment *ev, FW_CFixed units)
- {
- FW_ASSERT(fScrollBarHelper);
-
- #ifdef FW_BUILD_MAC
- fScrollBarHelper->SetMin(units.AsInt());
- #endif
-
- #ifdef FW_BUILD_WIN
- int min, max;
- fScrollBarHelper->GetScrollRange(min, max);
- fScrollBarHelper->SetScrollRange(units.AsInt(), max);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::SetScrollPos
- //----------------------------------------------------------------------------------------
-
- void FW_CScrollBar::SetScrollPos(Environment *ev, FW_CFixed units)
- {
- FW_ASSERT(fScrollBarHelper);
-
- #ifdef FW_BUILD_MAC
- fScrollBarHelper->SetValue(units.AsInt());
- #endif
-
- #ifdef FW_BUILD_WIN
- fScrollBarHelper->SetScrollPos(units.AsInt());
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CScrollBar::SetScrollPos
- //----------------------------------------------------------------------------------------
-
- void FW_CScrollBar::SetScrollPos(Environment *ev, FW_CFixed range, FW_CFixed pos)
- {
- FW_ASSERT(fScrollBarHelper);
-
- FW_CFixed units =
- FW_WideMultiply(GetScrollMax(ev) - GetScrollMin(ev), pos) / range + GetScrollMin(ev);
-
- #ifdef FW_BUILD_MAC
- fScrollBarHelper->SetValue(units.AsInt());
- #endif
-
- #ifdef FW_BUILD_WIN
- fScrollBarHelper->SetScrollPos(units.AsInt());
- #endif
- }
-